package D12_6z.反射和Properties_4;

import java.io.FileInputStream;
import java.lang.reflect.Method;
import java.util.Properties;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        Properties prop = new Properties();
        Class<?> aClass = Class.forName("Y2019.M12_.D12_6z.反射和Properties_4.User");
        Method setUid = aClass.getDeclaredMethod("setUid", String.class);
        Method setUsername = aClass.getDeclaredMethod("setUsername", String.class);
        Method setPassword = aClass.getDeclaredMethod("setPassword", String.class);
        FileInputStream in = new FileInputStream("src/Y2019/M12_/D12_6z/反射和Properties_4/data.properties");
        prop.load(in);
        in.close();
        System.out.println(prop);
        Object o = aClass.newInstance();
        setUid.invoke(o,prop.getProperty("uid"));
        setUsername.invoke(o,prop.getProperty("username"));
        setPassword.invoke(o,prop.getProperty("password"));
        Method toString = aClass.getDeclaredMethod("toString");
        toString.invoke(o,null);
    }
}
